package org.gwt.grin.rebind.features;

import java.util.Formatter;

import org.gwt.grin.client.features.InterpolatedModel;
import org.gwt.grin.rebind.SEFeature;
import org.gwt.grin.rebind.ShowBuilder;

public class SEFadeModel extends SEFeature {

	private final SEFade fade;

	public SEFadeModel(SEFade fade) {
		super(null);
		this.fade = fade;
	}

	@Override
	public String write(ShowBuilder builder) {
		Formatter formatter = new Formatter();
		formatter.format("makeFadeModel(\"%s\", %s, %s, %d, %d, %s)", getVN(builder),
				makeFrameArray(), makeFadeArray(), fade.repeatFrame,
				fade.loopCount, "null");
		return formatter.toString();
	}

	private String makeFrameArray() {
		StringBuilder sb = new StringBuilder();
		sb.append("new int[] {");
		boolean first = true;
		for (int a : fade.fs) {
			if (first) {
				first = false;
			} else {
				sb.append(", ");
			}
			sb.append(a);
		}
		sb.append("}");
		return sb.toString();
	}

	private String makeFadeArray() {
		StringBuilder sb = new StringBuilder();
		sb.append("new int[] {");
		boolean first = true;
		for (int f : fade.alphas) {
			if (first) {
				first = false;
			} else {
				sb.append(", ");
			}
			sb.append(f);
		}
		sb.append("}");
		return sb.toString();
	}

	@Override
	protected String getClassName() {
		return InterpolatedModel.class.getName();
	}

}
